#pragma once

#include "mission.h"
#include "mission_event.h"
#include "userAI.h"
#include "userAPI.h"
#include "assert.h"
#include "params.h"

using namespace std;
using namespace AI9;

class mission_manager
{
public:
	static mission_manager* get_intance() { return instance; }
	static mission_manager* instance;

	mission_manager()
	{
		instance = this;
		m_initialized = false;
		m_actioned = false;
		m_active_general = GeneralType::NUM_GENERALS;
	}

	bool isInitialized() const { return m_initialized; }

	void initialize(AI9::UserAI *ai);

	std::vector<AI9::ActionBase*> act();

	UserAPI &get_api() { return m_api; }

	void set_general_mission(GeneralType type, mission *m);
	void push_event(mission *from, mission *to, mission_event *e)
	{
		LOG << "push_back new event: " << e->get_type() << endl;
		event_item item;
		item.from = from;
		item.to = to;
		item.e = e;
		event_list.push_back(item);
	}

	bool actioned_state() { return m_actioned; } 
	GeneralType active_general() { return m_active_general; }

	void set_actioned_state(bool state)
	{
		m_actioned = state;
	}

	std::vector<AI9::ActionBase*> &get_action_queue() { return action_queue; }

protected:
	std::vector<AI9::ActionBase*> action_queue;
	std::map<GeneralType, mission*> general_mission;
	bool m_actioned;
	GeneralType m_active_general;

	struct event_item
	{
		mission *from, *to;
		mission_event *e;
	};
	
	std::list<event_item> event_list;
	bool m_initialized;
	UserAPI m_api;
	mission *root_mission;
};

